package xusage.cumulus.deployer.decider;

import java.io.IOException;
import java.net.URL;

import org.springframework.core.io.Resource;

import xusage.cumulus.deployer.AbstractDeployPathDecider;

public class FileDeployPathDecider extends AbstractDeployPathDecider {

	@Override
	public String decide(Resource resource) throws IOException {
		String resultPath = null;
		URL url = resource.getURL();
		if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
			String urlPath = url.getPath();
			String classPath = Thread.currentThread().getContextClassLoader().getResource("/").getPath();
			if (urlPath.startsWith(classPath)) {
				resultPath = context.getRealPath("/") + urlPath.substring(classPath.length());
			}
		}
		return resultPath;
	}

	public static final String FILE_PROTOCOL = "file";
}
